import java.util.Stack;

public class Solution2 {
    boolean isOperator(String s){
        return (s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/"));
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String str:tokens){
            if(!isOperator(str)){
                int x = Integer.parseInt(str);
                stack.push(x);
            }else{
                int val1 = stack.pop();
                int val2 = stack.pop();
                switch(str){
                    case "+":
                        stack.push(val2+val1);
                        break;
                    case "-":
                        stack.push(val2-val1);
                        break;
                    case "*":
                        stack.push(val2*val1);
                        break;
                    case "/":
                        stack.push(val2/val1);
                        break;
                }
            }
        }
        return stack.pop();
    }
}
